package userInterface;

import java.util.ArrayList;
import java.util.List;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.AbstractTableModel;

import model.Auction;


/**
 * 
 * @author Igor
 *
 */
@SuppressWarnings("serial")
public class ItemsAuctionTableModel extends AbstractTableModel implements ChangeListener {

    String[] columnNames = {"Auction name"};
    List<Auction> auctions = new ArrayList<Auction>();


    public void stateChanged(ChangeEvent arg0) {
        fireTableDataChanged();
    }

    public Auction getAuction(int index){
    	return auctions.get(index);
    }
    public String getColumnName(int col) {
        return columnNames[col];
    }

    public int getColumnCount() {
        return columnNames.length;
    }

    public void add(Auction a) {
        if (a != null) {
        	auctions.add(a);
            fireTableRowsInserted(auctions.size() - 1,
            		auctions.size() - 1);

            fireTableDataChanged();

        }
    }

    public void delete(int index) {
    	auctions.remove(index);

        fireTableDataChanged();

    }

    public int getRowCount() {
        return auctions.size();
    }

    public Object getValueAt(int row, int col) {
        Object val = null;
        switch (col) {
            case 0:
                val =  auctions.get(row).getName();
                break;

        }
        return val;
    }
}
